<% if @hat_requests.length == 0 %>
  No hat requests.
<% else %>
  <% @hat_requests.each_with_index do |hr,x| %>
    <% if x > 0 %>
      <hr>
    <% end %>

    <%= form_with model: hr, method: :post do |f| %>
      <div class="labelled_grid">
        <%= f.label :user_id, "User", :class => "required" %>
        <span>
          <%= styled_user_link hr.user %>
          <%= how_long_ago(hr.created_at) %>
        </span>

        <%= f.label :hat, "Hat", :class => "required" %>
        <%= f.text_field "hat" %>

        <%= f.label :link, "Link", :class => "required" %>
        <%= f.text_field "link" %>
        <% if hr.link.to_s.match(/^http/) %>
          <%= f.label :link, "Link", :class => "required" %>
          <a href="<%= hr.link %>" rel="ugc"><%= hr.link %></a>
        <% end %>

        <%= f.label :link, "Comment", :class => "required" %>
        <div class="shorten_first_p">
          <%= raw Markdowner.to_html(hr.comment || '') %>
        </div>
      </div>
    <% end %>

    <%= form_with model: hr, method: :post do |f| %>
      <div class="labelled_grid">
        <%= f.label :link, "Reason", :class => "required" %>
        <%= f.text_area :reason %>
      </div>
      <div class="row">
        <%= f.submit "Approve Hat Request", formaction: approve_hat_request_path(hr) %>
        <%= f.submit "Reject Hat Request", class: "deletion", formaction: reject_hat_request_path(hr)  %>
      </div>
    <% end %>
  <% end %>
<% end %>

